package com.ims.core.doc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ims.common.utils.poi.NewExcelUtil;
import com.ims.core.doc.controller.vo.CheckinInvoiceExcelVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ims.common.annotation.Log;
import com.ims.common.core.controller.BaseController;
import com.ims.common.core.domain.AjaxResult;
import com.ims.common.enums.BusinessType;
import com.ims.core.doc.domain.TInCheckinInvoice;
import com.ims.core.doc.service.ITInCheckinInvoiceService;
import com.ims.common.utils.poi.ExcelUtil;
import com.ims.common.core.page.TableDataInfo;

/**
 * 签收增值税发票Controller
 *
 * @author IMS
 * @date 2024-07-24
 */
@RestController
@RequestMapping("/doc/checkininvoice")
public class TInCheckinInvoiceController extends BaseController
{
    @Autowired
    private ITInCheckinInvoiceService tInCheckinInvoiceService;

    /**
     * 查询签收增值税发票列表
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInCheckinInvoice tInCheckinInvoice)
    {
        startPage();
        List<TInCheckinInvoice> list = tInCheckinInvoiceService.selectTInCheckinInvoiceList(tInCheckinInvoice);
        return getDataTable(list);
    }

    /**
     * 导出签收增值税发票列表
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:export')")
    @Log(title = "签收增值税发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInCheckinInvoice tInCheckinInvoice)
    {
        List<TInCheckinInvoice> list = tInCheckinInvoiceService.selectTInCheckinInvoiceList(tInCheckinInvoice);
        ExcelUtil<TInCheckinInvoice> util = new ExcelUtil<TInCheckinInvoice>(TInCheckinInvoice.class);
        util.exportExcel(response, list, "签收增值税发票数据");
    }

    /**
     * 获取签收增值税发票详细信息
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tInCheckinInvoiceService.selectTInCheckinInvoiceById(id));
    }

    /**
     * 新增签收增值税发票
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:add')")
    @Log(title = "签收增值税发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInCheckinInvoice tInCheckinInvoice)
    {
        return toAjax(tInCheckinInvoiceService.insertTInCheckinInvoice(tInCheckinInvoice));
    }

    /**
     * 修改签收增值税发票
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:edit')")
    @Log(title = "签收增值税发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInCheckinInvoice tInCheckinInvoice)
    {
        return toAjax(tInCheckinInvoiceService.updateTInCheckinInvoice(tInCheckinInvoice));
    }

    /**
     * 删除签收增值税发票
     */
    @PreAuthorize("@ss.hasPermi('doc:checkininvoice:remove')")
    @Log(title = "签收增值税发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInCheckinInvoiceService.deleteTInCheckinInvoiceByIds(ids));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        NewExcelUtil<CheckinInvoiceExcelVo> util = new NewExcelUtil<CheckinInvoiceExcelVo>(CheckinInvoiceExcelVo.class);
        util.importTemplateExcel(response, "发票签收导入模板");
    }
}
